<!-- 搜索表单 -->
<template>
  <el-form
    label-width="77px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="15">
      <el-col :lg="4" :md="12">
        <el-form-item label="账号:">
          <el-input
            clearable
            v-model="where.telphone"
            placeholder="请输入账号"
          />
        </el-form-item>
      </el-col>

      <el-col :lg="4" :md="12">
        <el-form-item label="操作类型:">
          <el-select
            v-model="where.type"
            placeholder="请选择"
            clearable
            class="ele-fluid"
          >
            <el-option label="充值" value="1" />
            <el-option label="扣除" value="2" />
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :lg="4" :md="12">
        <el-form-item label="使用类型:">
          <el-select
            v-model="where.way"
            placeholder="请选择"
            clearable
            class="ele-fluid"
          >
            <el-option label="后台" value="0" />
            <el-option label="充值" value="1" />
            <el-option label="视频合成线路一" value="6" />
            <el-option label="视频合成线路二" value="12" />
            <el-option label="视频合成线路三" value="9" />
            <el-option label="视频合成线路四" value="26" />
        
            <el-option label="声音克隆高保真" value="3" />
            <el-option label="声音克隆高保真合成" value="8" />
            <el-option label="ai文案创作" value="10" />
            <el-option label="视频提交文案" value="11" />
            <el-option label="专业版声音克隆" value="13" />
            <el-option label="专业版声音合成" value="14" />
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :lg="6" :md="12">
        <el-form-item label="操作时间:">
          <el-date-picker
            v-model="dateRange"
            type="datetimerange"
            :picker-options="pickerOptions"
            unlink-panels
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            class="ele-fluid"
          />
        </el-form-item>
      </el-col>

      <el-col :lg="6" :md="12">
        <div class="ele-form-actions">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="ele-btn-icon"
            @click="search"
          >
            查询
          </el-button>
          <el-button @click="reset">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
const DEFAULT_WHERE = {
  type: '',
  telphone: ''
};

export default {
  name: 'AccountSearch',
  data() {
    return {
      // 表单数据
      where: { ...DEFAULT_WHERE },
      dateRange: [],
      // 日期时间选择器快捷项
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }
        ]
      }
    };
  },
  methods: {
    handleChange() {
      this.search();
    },
    /* 搜索 */
    search() {
      const [d1, d2] = this.dateRange ?? [];
      this.$emit('search', {
        ...this.where,
        start_time: d1 ? d1 : '',
        end_time: d2 ? d2 : ''
      });
    },
    /*  重置 */
    reset() {
      this.where = { ...DEFAULT_WHERE };
      this.dateRange = [];
      this.search();
    }
  }
};
</script>
